home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0133_3D Rendering in TeleGame SDK.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  6KB  |  202 lines

  1. {
  2. I tested out an 8 bit DAC mode with a 3d rendered image for ANIVGA v1.2
  3. compatible TeleGame SDK.  There were portions of the image which actually
  4. popped out of the screen like a 3d movie.  Now very realistic 3d sprites and
  5. images are possible with TeleGame.  There is no impediment to display speed
  6. with this technique.  The higher color variation allows anti-aliasing and
  7. smooth blending.
  8.  
  9. Here is ATT 20c491 specific code from VGADOC3 for Orchid Fahrenheit VA/VLB:
  10. program Orchid;
  11. }
  12. uses ANIVGA, CRT;
  13. CONST
  14.       Pic1 = 'HIPALACE.PIC';
  15.       PalName = 'HI.PAL';
  16.       ch : Char = #0;
  17. VAR
  18.     i : Integer;
  19.     dac8 : Boolean;
  20.     DAC_RS2 : word;    {These address bits are fed to the }
  21.     {DAC_RS3 : word;    RS2 and RS3 pins of the palette chip}
  22.     daccomm : word;    { temp to trigger DAC reads }
  23.     Dac6Colors : Palette;     { 6 bit dac RGB values 0..63 }
  24.     Dac8Colors : Palette;     { 8 bit dac RGB values 0..255 }
  25. type
  26.   pel = record
  27.            index, red, green, blue : byte;
  28.         end;
  29. procedure disable;  {Disable interupts}
  30. begin
  31.   inline($fa);   { CLI instruction }
  32. end;  {disable}
  33. procedure enable;   {Enable interrupts}
  34. begin
  35.   inline($fb);   { STI instruction }
  36. end;  {enable}
  37. procedure outp(reg, val : word);  {Write the low byte of VAL to I/O port REG}
  38. begin
  39.   port[reg] := val;
  40. end;  {outp}
  41. function inp(reg : word) : byte;  {Reads a byte from I/O port REG}
  42. begin
  43.   reg := port[reg];
  44.   inp := reg;
  45. end;  {inp}
  46. function trigdac : word;  {Reads $3C6 4 times}
  47. var x : word;
  48. begin
  49.   x := inp($3c6);
  50.   x := inp($3c6);
  51.   x := inp($3c6);
  52.   trigdac := inp($3c6);
  53. end;
  54. procedure dac2pel;    {Force DAC back to PEL mode}
  55. begin
  56.   if inp($3c8)=0 then;
  57. end;  {dac2pel}
  58. procedure dac2comm;   {Enter command mode of HiColor DACs}
  59. begin
  60.   dac2pel;
  61.   daccomm := trigdac;
  62. end;  {dac2comm}
  63. procedure readpelreg(index : word; var p : pel);
  64. begin
  65.   p.index := index;
  66.   disable;
  67.   outp($3C7, index);
  68.   p.red   := inp($3C9);
  69.   p.blue  := inp($3C9);
  70.   p.green := inp($3C9);
  71.   enable;
  72. end;  {readpelreg}
  73. procedure writepelreg(var p : pel);
  74. begin
  75.   disable;
  76.   outp($3C8, p.index);
  77.   outp($3C9, p.red);
  78.   outp($3C9, p.blue);
  79.   outp($3C9, p.green);
  80.   enable;
  81. end;  {writepelreg}
  82. function setcomm(cmd : word) : word;
  83. begin
  84.   dac2comm;
  85.   outp($3c6, cmd);
  86.   dac2comm;
  87.   setcomm := inp($3c6);
  88. end;  {setcomm}
  89. function dacis8bit : boolean;
  90. var
  91.   pel2, x, v : word;
  92.   pel1 : pel;
  93. begin
  94.   pel2 := inp($3C8);
  95.   readpelreg(255, pel1);
  96.   v := pel1.red;
  97.   pel1.red := 255;
  98.   writepelreg(pel1);
  99.   readpelreg(255, pel1);
  100.   x := pel1.red;
  101.   pel1.red := v;
  102.   writepelreg(pel1);
  103.   outp($3C8, pel2);
  104.   dacis8bit := (x=255);
  105. end;  {dacis8bit}
  106. function prepDAC : word;     {Sets DAC up to receive command word}
  107. begin
  108.   dac2comm;
  109.   prepDAC := inp($3C6);
  110.   dac2comm;
  111. end;  {prepDAC}
  112. procedure dacmode(andmsk, ormsk : word);
  113. begin
  114.   ormsk := ormsk and (not andmsk);
  115.   if DAC_RS2 <> 0 then
  116.   begin
  117.     outp($3C6+DAC_RS2,(inp($3C6+DAC_RS2) AND andmsk) OR ormsk);
  118.   end
  119.   else begin
  120.     outp($3C6,(prepDAC AND andmsk) OR ormsk);
  121.     dac2pel;
  122.   end;
  123. end;  {dacmode}
  124. procedure testdac;      {Test for type of DAC}
  125. begin
  126.   DAC_RS2 := 0;
  127.   { DAC_RS3 := 0; }
  128. end;
  129. procedure setdac6;
  130. begin
  131.   dacmode(0, 0);
  132. end; {setdac6}
  133. procedure setdac8;
  134. begin
  135.   dacmode($FD, 2);
  136. end; {setdac8}
  137. BEGIN  {main}
  138.  testdac;
  139.  dac8 := false;          {default is normal VGA 6 bit RGB values}
  140.  InitGraph;
  141.  IF LoadPalette(PalName, 0, actualColors) =0
  142.   THEN BEGIN
  143.         CloseRoutines;
  144.         WRITELN('Couldn''t access file '+PalName+' : '+GetErrorMessage);
  145.         Halt
  146.        END
  147.   ELSE BEGIN
  148.        SetPalette(actualColors,TRUE);
  149.        move(actualColors, Dac6Colors, SizeOf(Palette));
  150.        END;
  151.  { sample 8 bit palette converted from a 6 bit palette }
  152.  move(actualColors, Dac8Colors, SizeOf(Palette));
  153.  { index, red, green, blue }
  154.  for i := 0 to 63 do begin
  155.         Dac8Colors[i].red       := i*4;
  156.         Dac8Colors[i].green     := 0;
  157.         Dac8Colors[i].blue      := 0;
  158.         Dac8Colors[i+$40].red   := 0;
  159.         Dac8Colors[i+$40].green := i*4;
  160.         Dac8Colors[i+$40].blue  := 0;
  161.         Dac8Colors[i+$80].red   := 0;
  162.         Dac8Colors[i+$80].green := 0;
  163.         Dac8Colors[i+$80].blue  := i*4;
  164.         Dac8Colors[i+$C0].red   := i*4;
  165.         Dac8Colors[i+$C0].green := i*4;
  166.         Dac8Colors[i+$C0].blue  := i*4;
  167.  end; {for}
  168.  LoadPage(Pic1, SCROLLPAGE);
  169.  GetBackgroundFromPage(SCROLLPAGE);
  170.  Animate; {just to initialize pages}
  171.     repeat
  172.          if keypressed then while keypressed do ch := upcase(readkey);
  173.          case ch of
  174.           'F': FadeIn(BACKGNDPAGE,2000,Fade_Squares);  { sample fade }
  175.           'P': begin                                   { pixel noise }
  176.                  FillPage(1-PAGE, Black);
  177.                  FOR i := 1 TO 20000 DO
  178.                  BEGIN
  179.                   PutPixel(Random(Succ(XMAX)),Random(Succ(YMAX)),Random(256));
  180.                  END;
  181.                end;
  182.           ' ': begin                         { Space toggles DAC 8/6 }
  183.                 dac8 := not dac8;
  184.                 if dac8 then begin
  185.                      setdac8;
  186.                      SetPalette(Dac8Colors, FALSE);
  187.                      OutTextXY(16,10,BACKGNDPAGE,'DAC=8');
  188.                      end
  189.                 else begin
  190.                      setdac6;
  191.                      SetPalette(Dac6Colors, FALSE);
  192.                      end;
  193.                end;
  194.          end; {case}
  195.     until (ch = #27)
  196.     setdac6;
  197.     dac2comm;     {Reset DAC}
  198.     outp($3c6,0);
  199.     dac2pel;
  200.  CloseRoutines;
  201. END.
  202.